class Group < ActiveRecord::Base
  
	stampable
	
	has_many :memberships, :dependent => :destroy
	has_many :users, :through => :memberships
	has_many :roles, :through => :memberships
	has_many :invitations, :dependent => :destroy
	
	after_create :make_default_manager
	
	def make_default_manager
		# The person who creates the Group becomes its first Member and default administrator
		member = Membership.new
		member.user = self.creator
		member.group = self
		member.role = Role.find_by_rolename('manager')
		member.save(false)
	end

end
